/**
 * Created by zcy-fover on 2017/3/26.
 */

/**
 * 通过JS控制文本的位置
 */
function messagePosition(){
    if (!document.getElementById){
        return false;
    }
    if (!document.getElementById("message")){
        return false;
    }
    var element = document.getElementById("message");
    element.style.position = "absolute";
    element.style.left = "500px";
    element.style.top = "200px";
}

/**
 * 结合时间控制元素位置的变化
 */
function moveMessage() {
    if (!document.getElementById){
        return false;
    }
    if (!document.getElementById("message")){
        return false;
    }
    var element = document.getElementById("message");

    var xpos = parseInt(element.style.left);
    var ypos = parseInt(element.style.top);

    // alert(xpos + "---" + ypos);

    if (xpos == 500 && ypos == 200){
        return true;
    }
    if (xpos < 500){
        xpos++;
    }
    if (xpos > 500){
        xpos--;
    }
    if (ypos < 200){
        ypos++;
    }
    if (ypos > 200){
        ypos--;
    }
    element.style.left = xpos + "px";
    element.style.top = ypos + "px";
    var movement = setTimeout("moveMessage()", 10);
}

// addLoadEvent(messagePosition);
addLoadEvent(moveMessage);